
/*
The following codes generate Tables 13 and 14.
*/




**********************************Table 12*********************************************
**********************************Table 12*********************************************
**********************************Table 12*********************************************



cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

bys newid: egen post_var=sd(post)
bys newid: egen miny=min(t)
bys newid: egen maxy=max(t)
*keep if maxy>2003 & miny<2001
keep if post_var>0

bys newid:egen wage_ave0=median(wage) if t<=2001
bys newid:egen wage_ave1=median(wage) if t>=2001

bys newid: egen wage0=mean(wage_ave0)
bys newid: egen wage1=mean(wage_ave1)

replace wage0=ln(wage0)
replace wage1=ln(wage1)

gen wagea=wage1-wage0

winsor2 wagea lnabsG , replace cuts(1 99) trim
gen ddd_wgrowth=did*wagea
gen wgrowth_post=wagea*post
 gen lnabsG_gdp=ln(absG_gdp)
 
 winsor2 tfp_op lnabsG_gdp lnage  finance2  lnkL rate , replace cuts(1 99) trim
*----------------------------
*13.1 Column 1: labor
*----------------------------
reghdfe lnabsG ddd_wgrowth  wgrowth_post did Ltfp_op  Llnage Llnl LlnkL Lfinance2 LlnRD   Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 

est sto lie1

*-------------------------------------------------------------------------------------------------

cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear
bys newid: egen post_var=sd(post)
*bys newid: egen miny=min(t)
keep if post_var>0
drop if dep_cur<=0
bys newid:egen k_ave0=mean(dep_cur) if t<=2001
bys newid:egen k_ave1=mean(dep_cur) if t>=2001

bys newid: egen k0=mean(k_ave0)
bys newid: egen k1=mean(k_ave1)

replace k0=ln(k0)
replace k1=ln(k1)
gen k_avea=(k1-k0)

winsor2 k_avea lnabsG, replace cuts(1 100) trim
gen ddd_kgrowth=did*k_avea
gen kgrowth_post=k_avea*post
*----------------------------
*13.2 Column 2: investment
*----------------------------
reghdfe lnabsG ddd_kgrowth  kgrowth_post did Ltfp_op   Llnage  LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 

est sto lie2


************************************************************************

cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear


bys newid: egen post_var=sd(post)
*bys newid: egen miny=min(t)
keep if post_var>0
egen ind4year=group(ind4_adj  t)
bys newid:egen intmed_ave0=median(intmed) if t<=2001
bys newid:egen intmed_ave1=median(intmed) if t>=2001

bys newid: egen intmed0=mean(intmed_ave0)
bys newid: egen intmed1=mean(intmed_ave1)

replace intmed0=ln(intmed0)
replace intmed1=ln(intmed1)
gen intmeda=(intmed1-intmed0)

winsor2 intmeda lnabsG, replace cuts(1 100) trim
gen ddd_intmedgrowth=did*intmeda
gen intmedgrowth_post=intmeda*post

*-------------------------------------
*13.3 Column 3: intermediate materials
*-------------------------------------
reghdfe lnabsG ddd_intmedgrowth  intmedgrowth_post did Ltfp_op   Llnage  LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 

est sto lie3
*****************************************************************



cd "D:\Nanjing\2020\wage gap\Replication"
use "data_input2.dta",clear

bys id: egen merge2=max(_merge)
bys id: egen merge_var=sd(_merge)
keep if _merge==3|_merge==2

bys newid: egen post_var=sd(post)
keep if post_var>0

gen treat_new=.
replace treat_new=0 if merge2==2

replace treat_new=1 if merge2==3&merge_var!=0
gen ddd_switch=did*treat_new
gen treat_new_post=treat_new*post

duplicates drop newid t,force

reghdfe lnabsG ddd_switch  treat_new_post did Ltfp_op   Llnage  LlnkL Lfinance2 ///
LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output ///
post_kl_1998 Lhhi5_lns_ind Llnk_ind if export_intensity<1, ///
absorb(t newid) vce(cluster ind4_adj) 
est sto lie4

*----------------------------------------------------------------------------------------

cd "D:\Nanjing\2020\wage gap\Replication"
use "data_input2.dta",clear

bys id: egen merge2=max(_merge)
keep if merge2==3|merge2==2

bys id: egen post_var=sd(post)
keep if post_var>0

gen import=intmed*import_inter_rate
replace import=0 if import==.

bys id:egen import_ave0=mean(import) if post==0
bys id:egen import_ave1=mean(import) if post==1

bys id: egen import0=mean(import_ave0)
bys id: egen import1=mean(import_ave1)

replace import0=log(1+import0)
replace import1=log(1+import1)

gen treat_growth=import1-import0
gen ddd_growth=did*treat_growth
gen treat_growth_post=treat_growth*post


duplicates drop newid t,force
*----------------------------  
* 13.5 column 5: intensity 
*----------------------------
reghdfe lnabsG ddd_growth  treat_growth_post did Ltfp_op   Llnage  LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 

 est sto lie5


**********************************************************************
cd "D:\Nanjing\2020\wage gap\Replication"
use "data_input2.dta",clear
replace import_num=0 if _merge==2

bys id: egen merge2=max(_merge)
keep if merge2==3|merge2==2

bys id: egen post_var=sd(post)
keep if post_var>0

bys id:egen importnum_ave0=mean(import_num) if post==0
bys id:egen importnum_ave1=mean(import_num) if post==1

bys id: egen importnum0=mean(importnum_ave0)
bys id: egen importnum1=mean(importnum_ave1)

replace importnum0=log(1+importnum0)
replace importnum1=log(1+importnum1)

gen treat_numgrowth=importnum1-importnum0
gen ddd_numgrowth=did*treat_numgrowth
gen treat_numgrowth_post=treat_numgrowth*post

duplicates drop newid t,force
*----------------------------
* 13.6 Column 6: Scope
*----------------------------
reghdfe lnabsG ddd_numgrowth treat_numgrowth_post did Ltfp_op   Llnage  LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 

 est sto lie6

**************************************************************************************
cd "D:\Nanjing\2020\wage gap\Replication"
use "data_input2.dta",clear
bys id: egen merge2=max(_merge)
keep if merge2==3|merge2==2

drop _merge
merge m:1 ind4_adj using "indrategrowth.dta"

gen ddd_indrategrowth=did*indrategrowth
gen indrategrowth_post=indrategrowth*post

duplicates drop newid t,force
*---------------------------------
* 13.7 column 7: Industry-level
*---------------------------------
reghdfe lnabsG ddd_indrategrowth indrategrowth_post  did Ltfp_op   Llnage  LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 
 est sto lie7
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
**********************************Table 13*********************************************
**********************************Table 13*********************************************
**********************************Table 13*********************************************




cd "D:\Nanjing\2020\wage gap\Replication"

use "labor-basic-tpu-reg-1.dta",clear
gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0

*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007



gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)
bys newid: egen post_var=sd(post)
bys newid: egen miny=min(t)
bys newid: egen maxy=max(t)
*keep if maxy>2003 & miny<2001
keep if post_var>0

bys newid:egen wage_ave0=mean(wage) if t<=2001
bys newid:egen wage_ave1=mean(wage) if t>=2001

bys newid: egen wage0=mean(wage_ave0)
bys newid: egen wage1=mean(wage_ave1)

replace wage0=ln(wage0)
replace wage1=ln(wage1)

gen wagea=wage1-wage0


gen ddd_wgrowth=did*wagea
gen wgrowth_post=wagea*post
 gen lnabsG_gdp=ln(absG_gdp)
 
 winsor2 tfp_op lnabs_k lnage  finance2  lnkL rate , replace cuts(1 99) trim
 
*----------------------------
*14.1 Column 1: labor
*----------------------------
reghdfe lnabs_k ddd_wgrowth  wgrowth_post did Ltfp_op  Llnage Llnl LlnkL Lfinance2 LlnRD   Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 


est sto lie1




*----------------------------
*14.2 Column 2: Investment
*----------------------------
cd "D:\Nanjing\2020\wage gap\Replication"

use "labor-basic-tpu-reg-1.dta",clear
gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0




*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007



gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)
bys newid: egen post_var=sd(post)
*bys newid: egen miny=min(t)
keep if post_var>0
drop if dep_cur<=0
bys newid:egen k_ave0=mean(dep_cur) if t<=2001
bys newid:egen k_ave1=mean(dep_cur) if t>2001

bys newid: egen k0=mean(k_ave0)
bys newid: egen k1=mean(k_ave1)

replace k0=ln(k0)
replace k1=ln(k1)
gen k_avea=(k1-k0)


gen ddd_kgrowth=did*k_avea
gen kgrowth_post=k_avea*post

winsor2  lnabs_k, replace cuts(0.5 100) trim
reghdfe lnabs_k ddd_kgrowth kgrowth_post did Ltfp_op   Llnage  LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 

est sto lie2
*-------------------------------------------------------------------------------------------------

*-----------------------------------------
*14.3 Column 3: Intermediate Materials
*-----------------------------------------
cd "D:\Nanjing\2020\wage gap\Replication"

use "labor-basic-tpu-reg-1.dta",clear
gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0




*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007



gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)


*bys newid: egen miny=min(t)



bys newid: egen post_var=sd(post)
*bys newid: egen miny=min(t)
keep if post_var>0
egen ind4year=group(ind4_adj  t)
bys newid:egen intmed_ave0=mean(intmed) if t<=2001
bys newid:egen intmed_ave1=mean(intmed) if t>2001

bys newid: egen intmed0=mean(intmed_ave0)
bys newid: egen intmed1=mean(intmed_ave1)

replace intmed0=ln(intmed0+1)
replace intmed1=ln(intmed1+1)
gen intmeda=(intmed1-intmed0)


gen ddd_intmedgrowth=did*intmeda
gen intmedgrowth_post=intmeda*post

winsor2 intmeda lnabs_k Ltfp_op lnRD , replace cuts(1 100) trim

reghdfe lnabs_k ddd_intmedgrowth  intmedgrowth_post did Ltfp_op   Llnage  LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind if export_intensity!=1, ///
absorb(t newid) vce(cluster ind4_adj) 


*****************************************************************

*----------------------------
*14.4 Column 4: Status
*----------------------------
cd "D:\Nanjing\2020\wage gap\Replication"

use "data_input2.dta",clear
gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0




*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007



gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)
bys id: egen merge2=max(_merge)
bys id: egen merge_var=sd(_merge)
keep if _merge==3|_merge==2

bys newid: egen post_var=sd(post)
keep if post_var>0

gen treat_new=.
replace treat_new=0 if merge2==2

replace treat_new=1 if merge2==3&merge_var!=0
gen ddd_switch=did*treat_new
gen treat_new_post=treat_new*post

duplicates drop newid t,force

reghdfe lnabs_k ddd_switch treat_new_post did Ltfp_op   Llnage  LlnkL Lfinance2 ///
LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output ///
post_kl_1998 Lhhi5_lns_ind Llnk_ind if export_intensity<1, ///
absorb(t newid) vce(cluster ind4_adj) 
est sto lie4

*----------------------------------------------------------------------------
*---------------------------------
*14.5 Column 5: Import Intensity
*---------------------------------
cd "D:\Nanjing\2020\wage gap\Replication"

use "data_input2.dta",clear

gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0




*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007



gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)
bys id: egen merge2=max(_merge)
keep if merge2==3|merge2==2

bys id: egen post_var=sd(post)
keep if post_var>0

gen import=intmed*import_inter_rate
replace import=0 if import==.

bys id:egen import_ave0=mean(import) if post==0
bys id:egen import_ave1=mean(import) if post==1

bys id: egen import0=mean(import_ave0)
bys id: egen import1=mean(import_ave1)

replace import0=log(1+import0)
replace import1=log(1+import1)

gen treat_growth=import1-import0
gen ddd_growth=did*treat_growth
gen treat_growth_post=treat_growth*post


duplicates drop newid t,force
  
reghdfe lnabs_k ddd_growth treat_growth_post did Ltfp_op   Llnage  LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 

 est sto lie5

*--------------------------------------------------------------------
*----------------------------
*14.6 Column 6: Scope
*----------------------------
cd "D:\Nanjing\2020\wage gap\Replication"

use "data_input2.dta",clear

gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0




*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007



gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)
replace import_num=0 if _merge==2

bys id: egen merge2=max(_merge)
keep if merge2==3|merge2==2

bys id: egen post_var=sd(post)
keep if post_var>0

bys id:egen importnum_ave0=mean(import_num) if post==0
bys id:egen importnum_ave1=mean(import_num) if post==1

bys id: egen importnum0=mean(importnum_ave0)
bys id: egen importnum1=mean(importnum_ave1)

replace importnum0=log(1+importnum0)
replace importnum1=log(1+importnum1)

gen treat_numgrowth=importnum1-importnum0
gen ddd_numgrowth=did*treat_numgrowth
gen treat_numgrowth_post=treat_numgrowth*post

duplicates drop newid t,force

reghdfe lnabs_k ddd_numgrowth treat_numgrowth_post did Ltfp_op   Llnage  LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind , ///
absorb(t newid) vce(cluster ind4_adj) 

 est sto lie6

 
 *--------------------------------------------------------------------------------------------
*----------------------------
*14.7 Column 7: Industry-Level
*----------------------------
cd "D:\Nanjing\2020\wage gap\Replication"

use "data_input2.dta",clear

gen VMPK=capitale*(y_ind_add1/k)






*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007



gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)
bys id: egen merge2=max(_merge)
keep if merge2==3|merge2==2

drop _merge
merge m:1 ind4_adj using "indrategrowth.dta"

gen ddd_indrategrowth=did*indrategrowth
gen indrategrowth_post=indrategrowth*post

winsor2  lnabs_k Ltfp_op lnRD , replace cuts(3 100) trim

reghdfe lnabs_k ddd_indrategrowth  indrategrowth_post did indrategrowth Ltfp_op   Llnage ///
 LlnkL Lfinance2 LlnRD Llnl  Lexport_intensity  Ltariff_input Ltariff_output ///
 post_kl_1998 Lhhi5_lns_ind Llnk_ind if export_intensity<1, ///
absorb(t newid) vce(cluster ind4_adj) 
 est sto lie7
 



 
